package com.sgb.kjwl.view.ui.adapter;


import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.SingleItemConstant;
import com.sgb.kjwl.model.entity.transport.SingleItemEntity;
import com.sgb.kjwl.utils.DefaultUtil;
import com.swgk.core.customview.SeeMoreView;

import java.util.List;

/**
 * @author: 杨畔
 * @date: 2020/12/29 16:59
 * @Description: 开票信息页面
 */
public class TransportInvoiceInfoAdapter extends BaseMultiItemQuickAdapter<SingleItemEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public TransportInvoiceInfoAdapter(List<SingleItemEntity> data) {
        super(data);
        //正常展示
        addItemType(SingleItemConstant.TYPE_ONE, R.layout.item_transport_invoice_one);
        //标题
        addItemType(SingleItemConstant.TYPE_TWO, R.layout.item_transport_invoice_two);
        //分割线
        addItemType(SingleItemConstant.TYPE_THREE, R.layout.item_transport_invoice_three);
        //付款方式
        addItemType(SingleItemConstant.TYPE_FOUR, R.layout.item_transport_invoice_four);
    }


    @Override
    protected void convert(BaseViewHolder helper, SingleItemEntity item) {
        switch (item.getItemType()) {
            case SingleItemConstant.TYPE_ONE:
                initNormal(helper, item);
                break;
            case SingleItemConstant.TYPE_TWO:
                initTitle(helper, item);
                break;
            case SingleItemConstant.TYPE_THREE:
                break;
            case SingleItemConstant.TYPE_FOUR:
                initFour(helper, item);
                break;
        }
    }

    private void initNormal(BaseViewHolder helper, SingleItemEntity item) {
        helper.setText(R.id.tv_item_title, item.getLeftString());
        //设置内容
        SeeMoreView moreView = helper.getView(R.id.tv_item_content);
        moreView.setText(DefaultUtil.getString(item.getRightString()));
    }

    private void initTitle(BaseViewHolder helper, SingleItemEntity item) {
        helper.setText(R.id.tv_item_title, item.getLeftString());
    }

    private void initFour(BaseViewHolder helper, SingleItemEntity item) {
        helper.setText(R.id.tv_item_title, item.getLeftString());
        //设置内容
        TextView moreView = helper.getView(R.id.tv_item_content);
        moreView.setText(DefaultUtil.getString(item.getRightString()));

        TextView tv = helper.getView(R.id.tv_item_content_ax);
        if (!TextUtils.isEmpty(item.getBottomString())) {
            tv.setVisibility(View.VISIBLE);
            tv.setText(DefaultUtil.getString(item.getBottomString()));
        } else {
            tv.setVisibility(View.GONE);
        }
    }
}
